package com.feisi.dao.sqlProvider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

public class CustomerSqlProvider {


    /**
     * 批量删除
     * @param ids
     * @return
     */
    public String deleteByIds(@Param("ids") Integer[] ids) {

        //delete from user where id in(?,?,?)
        SQL sql = new SQL();
        sql.DELETE_FROM("customer");//delete from customer

        //拼接条件: (#{ids[0]},#{ids[1]},#{ids[2]})
        StringBuilder sb = new StringBuilder();
        sb.append("(");
        for (int i = 0; i < ids.length; i++) {
            sb.append("#{ids["+i+"]},");
        }

        //删除最后一个多余的逗号
        sb.deleteCharAt(sb.length()-1);
        sb.append(")");
        System.out.println(sb.toString());
        //条件
        sql.WHERE("id in"+sb.toString());//where id in (...)
        System.out.println(sql.toString());
        return sql.toString();

    }
}
